/*
Project: 		The Impact of Short-Term Employment for Low-Income Youth: Experimental 	
				Evidence from the Philippines
Authors: 		Emily A. Beam and Stella Quimbo

***********************************
Path: 			code/02_analysis
File name: 		table_04.do 
***********************************

Purpose: 		Generates job characteristics for employed students

Inputs: 		spes_data.dta
Outputs: 		table_04.xls
																	

Log: 			results/03_output/log_table_04.log		

Last updated: 	18 November 2021
*/ 


cap log close 
log using "$output/log_table_04.log",replace


use "$usedata_analysis/spes_data",clear 

* Restrict to those in randomized sample who are working
keep if randomization == 1 & endline == 1
keep if _eeo_worknow == 1

*
* Generate outcome variables 

* Pull out missing values from baseline 

foreach var in _bb_workany _bb_workformal _bb_edulvl _bb_female{
replace `var' = . if _f`var' == 1
}

* Make wages conditional 
replace _eeo_wage_mn = . if _eeo_wage_mn == 0 

***********************************
* Restrict to employed respondents 



** Generate Table 

***********************************
#delimit ; 
local row " "Months employed" 	"Monthly wage" 				"Hours/week" 	
			"Share private" 	"Share public/non-profit" 	"Share OJT/internship" 	
			"Share salaried" 	"Share regular" 			"Started June 2016 or later" 	
			"Found through SPES"	"Found referral" 			"Applied directly"
			"Food service" 			"Sales" 					"Cleaning/laborer" 
			"Office" 				"Work experience" 			"Formal work experience" 
			"College level" 		"Female" "Observations""		; // 20 titles + Observations; 
local variables _eeo_months_emp			_eeo_wage_mn		_eeo_workhours	
				_eeo_worknow_private 	_eeo_worknow_pubn 	_eeo_ojt 				
				_eeo_salaried			_eeo_worker_reg		_eeo_worknow_new 
				_eeo_worknow_spes  		_eeo_found_ref 		_eeo_found_direct 
				_eeo_position1 			_eeo_position2 		_eeo_position6 
				_eeo_position5 
				_bb_workany 			_bb_workformal 
				_bb_edulvl 				_bb_female;


local col ""All"  "Not SPES" "SPES"";
matrix Q = J(21,3,.);
matrix rowname Q = `row';
matrix colname Q = `col';

* Loop;
local conditions ""if !missing(treatment)" "if spes_2016==0" "if spes_2016==1" ";


local j = 1;
foreach cond in `conditions' {;
	local i = 1;
	foreach var in `variables' {;
		qui summ `var' `cond';
		matrix Q[`i',`j']=r(mean);
		local ++i;
	};
	local ++j;
};


* Final row with number of observations;
local i = 1;
foreach cond in `conditions' {;
	qui count `cond';
	matrix Q[21,`i']=r(N);
	local ++i;
};
* Export to Excel;
putexcel set "$tables_analysis/table_04.xls", sheet(job_char) replace;
putexcel A1=matrix(Q`names'), nformat(###.##) names;


log close; 

exit; 
